import request from '@/utils/request'

/**
 * 获取员工的综合列表数据 (分页)
 * ***/
export const getEmployeeListAPI = (queryObj) => {
  return request({
    method: 'get',
    url: '/sys/user',
    params: queryObj
  })
}

/**
 * 删除员工
 */
export const delEmployeeAPI = (employeeID) => {
  return request({
    method: 'delete',
    url: `/sys/user/${employeeID}`
  })
}

/** **
 *  新增员工的接口
 * { username: '', timeOfEntry: '' }
 * **/
export const postEmployeeAPI = (employeeForm) => {
  return request({
    method: 'post',
    url: '/sys/user',
    data: employeeForm
  })
}

/**
 * 批量导入员工
 * @param {*} employeeList
 * @returns
 * [{}, {}, {}]
 */
export const postEmployeeBatchAPI = (employeeList) => {
  return request({
    method: 'post',
    url: '/sys/user/batch',
    data: employeeList
  })
}

/** *
 * 保存员工的基本信息
 * **/
export function putEmployeeAPI (userInfo) {
  return request({
    method: 'put',
    url: `/sys/user/${userInfo.id}`,
    data: userInfo
  })
}

/** *
 *  读取用户详情的基础信息 (个人详情-下面的接口)
 * **/
export function reqGetPersonalDetail (id) {
  return request({
    method: 'get',
    url: `/employees/${id}/personalInfo`
  })
}

/** *
 *  更新用户详情的基础信息 (个人详情-下面的接口)
 * **/
export function reqUpdatePersonal (data) {
  return request({
    method: 'put',
    url: `/employees/${data.userId}/personalInfo`,
    data
  })
}

/** **
 * 获取用户的岗位信息  (岗位信息)
 * ****/
export function reqGetJobDetail (id) {
  return request({
    method: 'get',
    url: `/employees/${id}/jobs`
  })
}

/**
 * 保存岗位信息  (岗位信息)
 * ****/
export function reqUpdateJob (data) {
  return request({
    method: 'put',
    url: `/employees/${data.userId}/jobs`,
    data
  })
}

/**
 * 给员工分配角色
 * @param {*} id
 * @param {*} roleIds
 */
export const putAssignRoleAPI = (id, roleIds) => {
  return request({
    method: 'put',
    url: '/sys/user/assignRoles',
    data: {
      id,
      roleIds
    }
  })
}
